Skip to content

fix(client): add missing Windows env vars to DEFAULT_INHERITED_ENV_VARS - #2043

Open
ChrisJr404 wants to merge 1 commit into
modelcontextprotocol:mainfrom
ChrisJr404:fix-default-inherited-env-vars-windows
Open

fix(client): add missing Windows env vars to DEFAULT_INHERITED_ENV_VARS#2043
ChrisJr404 wants to merge 1 commit into
modelcontextprotocol:mainfrom
ChrisJr404:fix-default-inherited-env-vars-windows

Conversation

@ChrisJr404

Copy link
Copy Markdown

Closes #2037.

On Windows, DEFAULT_INHERITED_ENV_VARS is missing a few variables that common dev tooling needs. The most impactful one is PATHEXT: without it, spawn('npm', ...) (and git, python, anything else that ships as .cmd/.exe/.bat) fails with ENOENT even when PATH is set, because Node has no extensions to try.

Added to the win32 branch:

  • PATHEXT — extensions Windows treats as executable. Fix for the spawn npm ENOENT symptom in the issue.
  • COMSPEC — path to cmd.exe; needed by spawn({ shell: true }) and anything that shells out.
  • PROGRAMFILES(X86) and PROGRAMW6432 — the other two Program Files paths. Tools that resolve install locations need at least one of these depending on whether the parent is 32-bit or 64-bit.
  • WINDIR — used by some legacy tooling that doesn't accept SYSTEMROOT.

Also sorted the array so future additions are easier to eyeball.

Test

Added a small assertion in stdio.test.ts that pins the expected list per platform, so a regression on either branch fails locally. pnpm test is green (365/365) and pnpm lint/pnpm typecheck are clean.

Changeset included as a patch bump on @modelcontextprotocol/client.

@ChrisJr404
ChrisJr404 requested a review from a team as a code owner May 11, 2026 13:55
@changeset-bot

changeset-bot Bot commented May 11, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a379b7a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
@modelcontextprotocol/client Patch
@modelcontextprotocol/core Patch
@modelcontextprotocol/server Patch
@modelcontextprotocol/server-legacy Patch
@modelcontextprotocol/codemod Patch
@modelcontextprotocol/core-internal Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented May 11, 2026

Copy link
Copy Markdown

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/@modelcontextprotocol/client@2043

@modelcontextprotocol/codemod

npm i https://pkg.pr.new/@modelcontextprotocol/codemod@2043

@modelcontextprotocol/core

npm i https://pkg.pr.new/@modelcontextprotocol/core@2043

@modelcontextprotocol/server

npm i https://pkg.pr.new/@modelcontextprotocol/server@2043

@modelcontextprotocol/server-legacy

npm i https://pkg.pr.new/@modelcontextprotocol/server-legacy@2043

@modelcontextprotocol/express

npm i https://pkg.pr.new/@modelcontextprotocol/express@2043

@modelcontextprotocol/fastify

npm i https://pkg.pr.new/@modelcontextprotocol/fastify@2043

@modelcontextprotocol/hono

npm i https://pkg.pr.new/@modelcontextprotocol/hono@2043

@modelcontextprotocol/node

npm i https://pkg.pr.new/@modelcontextprotocol/node@2043

commit: a379b7a

@daxian-dbw

Copy link
Copy Markdown

I can confirm this issue caused troubles to starting executables from within a local stdio MCP server, such as PowerShell, GitHub CLI, and etc.

Especially that PowerShell depends on PATHEXT to discover native executables. Without that environment variable, no native executable can be discovered within PowerShell on Windows.

@jspahrsummers and @anaisbetts, I found you made the decision to not include those environment vars in #36. Could you please give some attention to this fix?

@ChrisJr404

Copy link
Copy Markdown
Author

Rebased onto main. The only conflict was in stdio.test.ts from the import refactor and the new dispose/buffer tests — stdio.ts merged cleanly, all the new env vars are intact. daxian-dbw's confirmation about PowerShell/PATHEXT matches what we saw: without PATHEXT nothing native resolves. Ready for another look.

@ChrisJr404
ChrisJr404 force-pushed the fix-default-inherited-env-vars-windows branch from 8ebeb0d to a379b7a Compare August 17, 2026 22:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DEFAULT_INHERITED_ENV_VARS

2 participants